package cn.tedu.learn.tea.infrastructure;

import cn.tedu.learn.tea.dao.ContentDetailDao;
import cn.tedu.learn.tea.domain.bo.ContentDetailBO;
import cn.tedu.learn.tea.domain.repository.ContentDetailRepository;
import cn.tedu.learn.tea.infrastructure.data.converter.ContentDetailConverter;
import cn.tedu.learn.tea.po.ContentDetail;
import cn.tedu.learn.tea.protocol.parm.ContentParam;
import cn.tedu.learn.tea.protocol.parm.ContentUpdateParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

/**
 * 内容详情实现类
 */
@Repository
public class ContentDetailRepositoryImpl implements ContentDetailRepository {

    @Autowired
    private ContentDetailDao contentDetailDao;

    @Autowired
    private ContentDetailConverter contentDetailConverter;

    @Override
    public Integer insert(ContentParam contentParam) {
        ContentDetail contentDetail = contentDetailConverter.paramToPo(contentParam);
        return contentDetailDao.insert(contentDetail);
    }

    @Override
    public Integer update(ContentUpdateParam contentUpdateParam) {
        ContentDetail contentDetail = contentDetailConverter.paramToPo(contentUpdateParam);
        return contentDetailDao.update(contentDetail);
    }

    @Override
    public Integer delete(Integer contentId) {
        return contentDetailDao.delete(contentId);
    }

    @Override
    public ContentDetailBO selectContentDetailById(Integer contentId) {
        ContentDetail contentDetail = contentDetailDao.selectById(contentId);
        ContentDetailBO contentDetailBO = contentDetailConverter.poToBo(contentDetail);
        return contentDetailBO;
    }
}
